<?php

namespace Yj\Daos;


use App\Model\Model;
use App\Model\User;
use App\Model\User\UserMoney;
use App\Tool\Collect;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\GlobalScope;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Collection;


/**
 * @method $this search($params)
 * @mixin Builder|Model
 */
abstract class BaseDaos
{
    const MODEL = null;

    public function page($isPage = true)
    {
        _SetNotPage($isPage);
        return $this;
    }
    /**
     * @var Builder|\Hyperf\Database\Query\Builder|Model
     */
    public $model = null;

    public function __construct()
    {
        if (! is_null(static::MODEL)) {
            $modelClass = static::MODEL;
        }else{
            $modelClass = str_replace(['\Dao', 'Dao'], ['\Model', ''], get_class($this));
        }
        $this->model = App($modelClass);
    }

    public function __call($method, $parameters)
    {
        return call([$this->newSearchQuery(), $method], $parameters);
    }

//    abstract public function searchParams();


    public function newSearchQuery()
    {
        return $this->newSearch()->setDao($this);
    }

    public function getNewModel()
    {
        return $this->model::query();
    }

    public function getSearch()
    {
        return $this->model::query();
    }

    public function newSearch()
    {
        return new Search();
    }


}